import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:get/get.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mall/modules/model/goods_detail_entity.dart';
import 'package:mall/utils/image_component/image_component.dart';
import 'package:mall/utils/image_component/image_preview_dialog.dart';

class GoodsDetailSwiperWidget extends StatelessWidget {
  final GoodsDetailEntity _goodsDetailEntity;

  GoodsDetailSwiperWidget(this._goodsDetailEntity);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 344.h,
      child: Swiper(
        itemCount: _goodsDetailEntity.info?.gallery == null ? 0 : _goodsDetailEntity.info!.gallery!.length,
        scrollDirection: Axis.horizontal,
        //滚动方向，设置为Axis.vertical如果需要垂直滚动
        loop: true,
        //无限轮播模式开关
        index: 0,
        //初始的时候下标位置
        autoplay: false,
        itemBuilder: (BuildContext buildContext, int index) {
          return ImageComponent(_goodsDetailEntity.info?.gallery?[index]);
        },
        onTap: (index) {
          Get.dialog(ImagePreviewDialog(imgList: _goodsDetailEntity.info!.gallery!, index: index));
        },
        duration: 10000,
        pagination: SwiperPagination(
            alignment: Alignment.bottomCenter,
            builder: DotSwiperPaginationBuilder(
                size: 6, activeSize: 6, color: Colors.white, activeColor: AppColors.C_FF5722)),
      ),
    );
  }
}
